<?php  
	require_once 'dbHandler.php';
	/**************************************************
	 * This class is for all generic queries for all of somthing
	 * such as all salads or all soups, or all ingredients.
	 ***************************************************/
	class Item
	{
		private $list;
		
		public function __construct()
		{
			$this->list = "";
		}
			
		public function getAppetizers()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM item WHERE category = 'Appetizers' and availability = 'Y'";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		
		public function getSoups()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM item WHERE category = 'Soups' and availability = 'Y'";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		
		public function getSalads()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM item WHERE category = 'Salads' and availability = 'Y'";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		
	public function getAllAppetizers()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM item WHERE category = 'Appetizers'";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		
		public function getAllSoups()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM item WHERE category = 'Soups'";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		
		public function getAllSalads()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM item WHERE category = 'Salads'";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		
		public function getAllIngredients()
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT * FROM ingredient";
			$this->list = $DTB->query($query);
			return $this->list;
		}
		public function DisplayItems($inarray)
		{
			$html = "";
			while($row = mysql_fetch_array($inarray))
			{
				$name = $row['name'];
				$price = $row['price'];
				$Iid = $row['no'];
				$ava = $row['availability'];
				$html .= '<input type= "radio" name = "ITM" value='.$Iid.'>'.$name.'...$'.$price.'...Avaliable : '.$ava.'</input><br/>';
			}
			echo $html;
		}
		public function DisplayIngredients($inarray)
		{
			$html = "";
			while($row = mysql_fetch_array($inarray))
	  		{
	  			$name = $row['name'];
	  			$html .= "<b>Name: " . $row['name'] . "....Quantity: " . $row['quantity'] . "....Price: $" . $row['price'] ."</b><br>";
	  			$html .= "<form action='Ingredients.php' method='post'>";
	  			$html .= "<input type='hidden' name='order' value='$name'/>";
				$html .= "<input type='submit' name='Order 100 more' value='Order 100 more'/></form><br><br>";
	  		}
	  		echo $html;
		}
		public function setItemavaliable($itemid)
		{
			$DTB = dbHandler::getInstance();
			$query = "UPDATE item SET availability = 'Y' WHERE no='$itemid'";
			$result = $DTB->query($query);
		}
		public function setItemtoNotAvaliable($itemid)
		{
			$DTB = dbHandler::getInstance();
			$query = "UPDATE item SET availability = 'N' WHERE no='$itemid'";
			$result = $DTB->query($query);
		}
		public function changeitemprice($itemid,$newPrice)
		{
			$DTB = dbHandler::getInstance();
			$query = "UPDATE item SET price = '$newPrice' WHERE no='$itemid'";
			$result = $DTB->query($query);
		}
		public function Add100Quan($ingid)
		{
			$DTB = dbHandler::getInstance();
			$query = "SELECT quantity FROM ingredient WHERE name = '$ingid'";
			$result = $DTB->query($query);
			$current = mysql_result($result,0,'quantity');
			$current += 100;
			$query = "UPDATE ingredient SET quantity = '$current' WHERE name='$ingid'";
			$result = $DTB->query($query);
		}
		public function AddnewIngredient($name,$quan,$price)
		{
			$DTB = dbHandler::getInstance();
			$query = "INSERT INTO ingredient VALUES('$name','$quan','$price')";
			$result = $DTB->query($query);
		}
		
		public function addItem($name, $category, $price, $description)
		{
			$DTB = dbHandler::getInstance();
			$availability = "Y";
			$query = "INSERT INTO item(" . 
			 " name," .
			 " price," .
			 " category," .
			 " description," .
			 " availability)" .
			 " VALUES('" .
			 $name . "', '" .
			 $price . "', '" .
			 $category . "', '" .
			 $description . "', '" .
			 $availability . 
			 "')";
			return $DTB->query($query);
		}
	}
	
	?>
	